package com.example.presentshopping.ui.activity

import BaseRecyclerAdapter
import BaseRecyclerHolder
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import com.example.presentshopping.R
import com.example.presentshopping.config.base.BaseMvpActivity
import com.example.presentshopping.config.bean.OrderDetailsBean
import com.example.presentshopping.config.bean.SpecialOrderBean
import com.example.presentshopping.mvp.presenter.PublicPresenter
import com.example.presentshopping.net.http.HttpRequest
import com.example.presentshopping.net.http.HttpURL
import com.example.presentshopping.utils.tool.GsonUtils
import kotlinx.android.synthetic.main.activity_order_details.*


//
class OrderDetailsActivity : BaseMvpActivity() {

    var OrderDetails: OrderDetailsBean? = null

    var baseRecyclerAdapter: BaseRecyclerAdapter<OrderDetailsBean.DataBean>? = null
    var id: String? = null
    private var queryInfoPresenter: PublicPresenter? = null
    override val layoutId: Int
        get() = R.layout.activity_order_details

    override fun initView(savedInstanceState: Bundle?) {
        queryInfoPresenter = PublicPresenter(this, false, "")
        queryInfoPresenter?.attachView(this)
        title_main_tv.leftBackImageTv.setOnClickListener { finish() }
        title_main_tv.titleTv.text = "物流详情"
        id = intent?.getStringExtra("id")
        setAdapter()
        OrderDetails(id)

    }

    fun setAdapter() {
        baseRecyclerAdapter = object :
            BaseRecyclerAdapter<OrderDetailsBean.DataBean>(this, null, R.layout.order_details) {
            override fun convert(
                holder: BaseRecyclerHolder?,
                data: OrderDetailsBean.DataBean,
                position: Int,
                isScrolling: Boolean,
                selectedPosition: Int
            ) {
                val tvAcceptTime = holder?.getView<TextView>(R.id.tvAcceptTime)
                val tvAcceptStation = holder?.getView<TextView>(R.id.tvAcceptStation)
                tvAcceptTime?.text = data.time
                tvAcceptStation?.text = data.context
            }
        }
        order_rct.adapter = baseRecyclerAdapter
    }

    fun OrderDetails(id: String?) {
        queryInfoPresenter?.netWorkRequestPost(HttpURL.Req_getOrderDetail,
            HttpRequest.getGoodsDetail(id))
    }

    override fun onDestroy() {
        queryInfoPresenter?.detachView()
        super.onDestroy()
    }

    override fun showToast(msg: String?) {

    }

    override fun onFailure(e: Throwable?, code: Int, msg: String?, isNetWorkError: Boolean) {
        order_rct.loadMoreFinish(true,false)
    }

    override fun onSuccess(data: String?) {
        OrderDetails = GsonUtils.getGson().fromJson(data, OrderDetailsBean().javaClass)
        if (OrderDetails?.data?.size!!>0){
            baseRecyclerAdapter?.setData(OrderDetails?.data)
        }else{
            order_rct.loadMoreFinish(true,false)
        }


    }
}